#encoding=utf-8
#反转一个数字
def reverseint(n):
    '''unittest
    >>> reverseint(12345)
    54321
    >>> reverseint(0)
    0
    >>> reverseint(-10)
    -1
    >>> reverseint(120)
    21
    '''
    number = n
    bMinus = False
    if n < 0:
      number = abs(number)
      bMinus = True
    else:
        bMinus = False
    
    a = []
    while True:
      a.append(number % 10)
      number = number /10
      if number == 0:
          break
    
    newvalue = 0
    for i in range(len(a)):
        newvalue = 10 * newvalue + a[i]
      
    if bMinus:
        return 0-newvalue
    else:
        return newvalue

import doctest
doctest.testmod()